import React, { useEffect } from 'react'
import Son2 from './Son2'
import PubSub from 'pubsub-js'
export default function Father2() {
  useEffect(() => {
    // 订阅消息
    let son2Id = PubSub.subscribe('msg', (msg, data) => {
      // msg 是 发布的消息名称
      // data 是 发布的消息数据
      console.log('----- Father2 组件 -----')
      console.log('son2接收到了消息', msg)
      console.log('son2接收到了数据', data)
      console.log('----- Father2 End -----')
    })

    return () => {
      PubSub.unsubscribe(son2Id)
    }
  }, [])
  return (
    <div>
      <h2>父2组件</h2>

      <Son2 />
    </div>
  )
}
